/**
 * @param {number[]} height
 * @return {number}
 */
var maxArea = function(height) {
  let i = 0, j = height.length - 1, result = 0;
  while(i < j) {
    let capacity = (j - i) * Math.min(height[i], height[j]);
    result = Math.max(result, capacity);
    if(height[i] < height[j]) {
      i++;
    } else {
      j--;
    }
  }
  return result;
};

let height = [1,8,6,2,5,4,8,3,7];
console.log(maxArea(height));
height = [1,1];
console.log(maxArea(height));
